package com.yaofeng.mybatis.modules.sys.controller;

import com.yaofeng.mybatis.annotation.Log;
import com.yaofeng.mybatis.common.ResponseInfo;
import com.yaofeng.mybatis.modules.sys.entity.User;
import com.yaofeng.mybatis.modules.sys.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 用户登录和退出Controller
 * Created by yaofeng on 2019/8/30.
 */

@RestController
@RequestMapping("/sys/auth")
public class UserLoginController {

    @Autowired
    private IUserService iUserService;

    /**
     * 用户登录认证
     *
     * @return
     */
    @PostMapping("/login")
    @Log(ignore = true)
    public ResponseInfo login(@RequestBody User user) throws Exception {
        Object jwtToken = iUserService.login(user.getLoginName(), user.getUserPassword());
        return ResponseInfo.success(jwtToken);
    }


    @PostMapping("/logout")
    public ResponseInfo logOut() {
        iUserService.logOut();
        return ResponseInfo.success();
    }

}
